using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace GetSharePointToValidate.FeatureCollection
{
    public class FeatureReceiverModifierWebconfig : SPFeatureReceiver
    {
        private const string PATH = "configuration/system.web";
        private const string OWNER = "GSPTV";
        private const string NAME = "xhtmlConformance[@mode='Strict']";
        private const string VALIE = "<xhtmlConformance mode=\"Strict\"/>";
        private const int SEQUENCE = 0;

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;
            SPWebConfigModification xhtmlConformanceModification = new SPWebConfigModification(NAME, PATH);   
            xhtmlConformanceModification.Value = VALIE;
            xhtmlConformanceModification.Owner = OWNER;
            xhtmlConformanceModification.Sequence = SEQUENCE;   
            xhtmlConformanceModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

            webApplication.WebConfigModifications.Add(xhtmlConformanceModification);
            webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
            webApplication.Update(); 

        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;
            Deployment.RemoveWebConfigModificationFromWebconfig rwcmfw = new GetSharePointToValidate.Deployment.RemoveWebConfigModificationFromWebconfig();
            rwcmfw.RemoveConfiguration(webApplication, OWNER);
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            
        }
    }
}
